package com.abel.bigwater.data.jnrq

import com.abel.bigmeter.service.MeterParam
import com.abel.bigwater.data.BcdString
import com.abel.bigwater.data.BwDataAnjiApplication
import com.abel.bigwater.data.MsgHelper
import com.alibaba.fastjson.JSON
import io.netty.buffer.Unpooled
import io.netty.channel.embedded.EmbeddedChannel
import org.joda.time.DateTime
import org.junit.AfterClass
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner::class)
@SpringBootTest
//@ActiveProfiles("test")
class JnrqTcpHandlerTest {
    @Autowired
    var app: BwDataAnjiApplication? = null

    @Autowired
    var msgHelper: MsgHelper? = null

    var ch: EmbeddedChannel? = null

    @Before
    fun beforeTest() {
        ch = EmbeddedChannel(JnrqDecoder("11", "zn-", msgHelper!!), JnrqTcpHandler(
                app!!.dataMapper!!,
                app!!.rtuMapper!!,
                app!!.firmId!!,
                app!!.firmCode!!,
                msgHelper!!,
                app!!.deviceTemplate!!))
    }

    @Test
    fun testMapper() {
        val rtuList = app!!.rtuMapper!!.selectRtuList(MeterParam(firmId = "23"))
        lgr.info("rtu-list: ${JSON.toJSONString(rtuList, true)}")
    }

    /** 68 11 55 46 11 22 33 44 19 00 00 00 00 12 00 00 0a 13 00 00 02 03 0b 0d 0a
     * Empty (from product):
     * 68 11 55 46 32 12 00 00 19 00 00 00 00 12 00 00 0a 13 00 00 02 03 0b 0d 0a
     * Hist (from product):
     * 68 11 55 46 34 12 00 00 49 00 01 00 00 1f 00 00 00 00 70 01 29 0c 45 16 81 00 00 00 00 d8 26 01
    00 01 01 db 07 00 00 00 00 00 08 00 00 c7 01 00 00 00 00 00 00 d9 27 01 00 01 01 db 07 00 00 00
    00 00 08 00 00 ee d3 0d 0a
     */
    @Test
    fun testEmpty() {
        val p1 = JnrqPacket().apply {
            packetType = PacketType.UploadHistoryEmpty
            devAddrInt = 0x11223344
        }
        val mpty = UploadEmptyData(p1).apply {
            rssi = 18
            sendPacketCount = 10
            recvPacketCount = 19
            replyCnt = 3
            swVersion = 2
        }
        p1.data = mpty

        val r1 = ch!!.writeInbound(Unpooled.buffer().also { p1.fillBuffer(it) })

        lgr.info("result: ${JSON.toJSONString(r1, true)}")
    }

    /**
     *
     * 68 11 55 46 22 33 44 56 31 00 01 00 00 13 00 00 02 0c 4e 0f 03 00 22 33 44 56 05 06 07 08 00 00
    05 01 07 18 20 00 67 45 23 01 00 00 00 00 38 0d 0a
     */
    @Test
    fun testHist() {
        val p1 = JnrqPacket().apply {
            packetType = PacketType.UploadHistoryEmpty
            devAddrInt = 0x22334456
        }

        val hist = UploadHistoryData(p1).apply {
            dataType = JnrqDataType.WaterMeter
            rssi = 19
            sendPacketCount = 2
            recvPacketCount = 12
            volt = 690
            aiNo = 15
            swVersion = 3

            waterList = arrayOf(WaterMeterData().apply {
                meterAddrStr = BcdString(byteArrayOf(22, 33, 44, 56, 5, 6, 7, 8), true)
                readStatus = ReadStatusType.Success
                sampleTime = DateTime(2018, 7, 1, 5, 0).toDate()
                waterDigits = 12345.67
                reserved = BcdString(byteArrayOf(0, 0), false)
            })
        }

        p1.data = hist

        val r1 = if (ch!!.isWritable) {
            ch!!.writeInbound(Unpooled.buffer().also { p1.fillBuffer(it) })
        } else null
        lgr.info("result for hist: ${JSON.toJSONString(r1, true)}")
    }

    /**下发地址包:
    68 11 55 44 34 12 00 00 43 03 00 00 01 01 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    82 01 42 10 09 00 16 95 82 01 42 10 09 00 16 96 82 01 42 10 09 00 16 97 82 01 42 10 09 00 16 99
    82 01 42 10 09 00 17 00 82 01 42 10 09 00 51 01 82 01 42 10 09 00 51 02 82 01 42 10 09 00 51 03
    82 01 42 10 09 00 51 04 82 01 42 10 09 00 51 05 82 01 42 10 09 00 51 06 82 01 42 10 09 00 51 07
    82 01 42 10 09 00 51 08 82 01 42 10 09 00 51 09 82 01 42 10 09 00 51 11 82 01 42 10 09 00 51 12
    82 01 42 10 09 00 51 13 82 01 42 10 09 00 51 14 82 01 42 10 09 00 51 15 82 01 42 10 09 00 51 16
    82 01 42 10 09 00 51 17 82 01 42 10 09 00 51 18 82 01 42 10 09 00 51 19 82 01 42 10 09 00 51 20
    82 01 42 10 09 00 51 21 82 01 42 10 09 00 51 22 82 01 42 10 09 00 51 23 82 01 42 10 09 00 51 24
    82 01 42 10 09 00 51 25 82 01 42 10 09 00 51 26 82 01 42 10 06 00 54 81 82 01 42 10 09 00 13 07
    82 01 42 10 09 00 13 08 82 01 42 10 09 00 13 12 82 01 42 10 09 00 13 14 82 01 42 10 09 00 13 24
    82 01 42 10 09 00 13 26 82 01 42 10 09 00 13 27 82 01 42 10 09 00 13 31 82 01 42 10 09 00 13 32
    82 01 42 10 09 00 13 33 82 01 42 10 09 00 13 35 82 01 42 10 09 00 13 38 82 01 42 10 09 00 13 39
    82 01 42 10 09 00 13 42 82 01 42 10 09 00 74 10 82 01 42 10 09 00 74 11 82 01 42 10 09 00 74 13
    82 01 42 10 09 00 74 14 82 01 42 10 09 00 74 15 82 01 42 10 09 00 74 16 82 01 42 10 09 00 74 17
    82 01 42 10 09 00 74 19 82 01 42 10 09 00 74 20 82 01 42 10 09 00 74 21 82 01 42 10 09 00 74 22
    82 01 42 10 09 00 74 23 82 01 42 10 09 00 74 24 82 01 42 10 09 00 74 25 82 01 42 10 09 00 74 26
    82 01 42 10 09 00 51 27 82 01 42 10 09 00 51 28 82 01 42 10 09 00 51 29 82 01 42 10 09 00 51 30
    82 01 42 10 09 00 51 31 82 01 42 10 09 00 51 32 82 01 42 10 09 00 51 33 82 01 42 10 09 00 51 34
    82 01 42 10 09 00 51 35 82 01 42 10 09 00 51 36 82 01 42 10 09 00 51 37 82 01 42 10 09 00 51 38
    82 01 42 10 09 00 51 39 82 01 42 10 09 00 51 40 82 01 42 10 09 00 51 41 82 01 42 10 09 00 69 94
    82 01 42 10 09 00 69 93 82 01 42 10 09 00 69 97 82 01 42 10 09 00 69 98 82 01 42 10 09 00 70 00
    82 01 42 10 09 00 69 95 82 01 42 10 09 00 69 99 82 01 42 10 09 00 74 51 82 01 42 10 09 00 74 53
    82 01 42 10 09 00 74 57 82 01 42 10 09 00 74 54 82 01 42 10 09 00 74 56 82 01 42 10 09 00 74 58
    82 01 42 10 09 00 74 52 82 01 42 10 09 00 60 54 82 01 42 10 09 00 60 67 82 01 42 10 09 00 60 76
    82 01 42 10 09 00 60 61 82 01 42 10 09 00 60 84 82 01 42 10 09 00 60 73 82 01 42 10 09 00 60 72
    82 01 42 10 09 00 60 71 82 01 42 10 09 00 60 62 82 01 42 10 09 00 60 69 82 01 42 10 09 00 60 58
    0b 0d 0a
     * 下发校时包:
    68 11 55 42 34 12 00 00 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 12 13 20
    07 18 20 00 00 00 06 00 00 10 00 00 00 18 00 00 28 00 00 00 00 00 6b 0d 0a
     */
    @Test
    fun testDownload() {
        val p1 = JnrqPacket().apply {
            packetType = PacketType.UploadHistoryEmpty
            devAddrInt = 0x1234
        }

        val mpty = UploadEmptyData(p1).apply {
            rssi = 18
            sendPacketCount = 10
            recvPacketCount = 19
            replyCnt = 3
            swVersion = 41
        }
        p1.data = mpty


        ch!!.writeInbound(Unpooled.buffer().apply { p1.fillBuffer(this) })

        Thread.sleep(2000)
    }

    @Test
    fun testUpdateIp() {
        val p1 = JnrqPacket().apply {
            packetType = PacketType.UploadHistoryEmpty
            devAddrInt = 0x5678

            data = UploadEmptyData(this).also {
                it.rssi = 10
                it.replyCnt = 100
                it.swVersion = 29
                it.sendPacketCount = 18
                it.recvPacketCount = 19
            }
        }

        val buf = Unpooled.buffer().also { p1.fillBuffer(it) }
        lgr.info("${BcdString.hexString(buf, buf.readableBytes(), true)}")
    }

    @Test
    fun testParseDownload() {
        val str = """
    68 11 55 44 34 12 00 00 43 03 00 00 01 01 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    82 01 42 10 09 00 16 95 82 01 42 10 09 00 16 96 82 01 42 10 09 00 16 97 82 01 42 10 09 00 16 99
    82 01 42 10 09 00 17 00 82 01 42 10 09 00 51 01 82 01 42 10 09 00 51 02 82 01 42 10 09 00 51 03
    82 01 42 10 09 00 51 04 82 01 42 10 09 00 51 05 82 01 42 10 09 00 51 06 82 01 42 10 09 00 51 07
    82 01 42 10 09 00 51 08 82 01 42 10 09 00 51 09 82 01 42 10 09 00 51 11 82 01 42 10 09 00 51 12
    82 01 42 10 09 00 51 13 82 01 42 10 09 00 51 14 82 01 42 10 09 00 51 15 82 01 42 10 09 00 51 16
    82 01 42 10 09 00 51 17 82 01 42 10 09 00 51 18 82 01 42 10 09 00 51 19 82 01 42 10 09 00 51 20
    82 01 42 10 09 00 51 21 82 01 42 10 09 00 51 22 82 01 42 10 09 00 51 23 82 01 42 10 09 00 51 24
    82 01 42 10 09 00 51 25 82 01 42 10 09 00 51 26 82 01 42 10 06 00 54 81 82 01 42 10 09 00 13 07
    82 01 42 10 09 00 13 08 82 01 42 10 09 00 13 12 82 01 42 10 09 00 13 14 82 01 42 10 09 00 13 24
    82 01 42 10 09 00 13 26 82 01 42 10 09 00 13 27 82 01 42 10 09 00 13 31 82 01 42 10 09 00 13 32
    82 01 42 10 09 00 13 33 82 01 42 10 09 00 13 35 82 01 42 10 09 00 13 38 82 01 42 10 09 00 13 39
    82 01 42 10 09 00 13 42 82 01 42 10 09 00 74 10 82 01 42 10 09 00 74 11 82 01 42 10 09 00 74 13
    82 01 42 10 09 00 74 14 82 01 42 10 09 00 74 15 82 01 42 10 09 00 74 16 82 01 42 10 09 00 74 17
    82 01 42 10 09 00 74 19 82 01 42 10 09 00 74 20 82 01 42 10 09 00 74 21 82 01 42 10 09 00 74 22
    82 01 42 10 09 00 74 23 82 01 42 10 09 00 74 24 82 01 42 10 09 00 74 25 82 01 42 10 09 00 74 26
    82 01 42 10 09 00 51 27 82 01 42 10 09 00 51 28 82 01 42 10 09 00 51 29 82 01 42 10 09 00 51 30
    82 01 42 10 09 00 51 31 82 01 42 10 09 00 51 32 82 01 42 10 09 00 51 33 82 01 42 10 09 00 51 34
    82 01 42 10 09 00 51 35 82 01 42 10 09 00 51 36 82 01 42 10 09 00 51 37 82 01 42 10 09 00 51 38
    82 01 42 10 09 00 51 39 82 01 42 10 09 00 51 40 82 01 42 10 09 00 51 41 82 01 42 10 09 00 69 94
    82 01 42 10 09 00 69 93 82 01 42 10 09 00 69 97 82 01 42 10 09 00 69 98 82 01 42 10 09 00 70 00
    82 01 42 10 09 00 69 95 82 01 42 10 09 00 69 99 82 01 42 10 09 00 74 51 82 01 42 10 09 00 74 53
    82 01 42 10 09 00 74 57 82 01 42 10 09 00 74 54 82 01 42 10 09 00 74 56 82 01 42 10 09 00 74 58
    82 01 42 10 09 00 74 52 82 01 42 10 09 00 60 54 82 01 42 10 09 00 60 67 82 01 42 10 09 00 60 76
    82 01 42 10 09 00 60 61 82 01 42 10 09 00 60 84 82 01 42 10 09 00 60 73 82 01 42 10 09 00 60 72
    82 01 42 10 09 00 60 71 82 01 42 10 09 00 60 62 82 01 42 10 09 00 60 69 82 01 42 10 09 00 60 58
    0b 0d 0a"""
        val p1 = JnrqPacket.parseBuffer(Unpooled.buffer().apply { writeBytes(BcdString.fromBcdString(str).hexArray) })
        lgr.info("${JSON.toJSONString(p1, true)}")
    }

    @Test
    fun testParseOkay() {
        val str = """68115546F1930000A1020100000F0000BDBD713729057302031620420181032E0C1507E2070000000000080000007402031620420181232E0C1507E2070000000000080000007502031620420181062F0C1507E2070000000000080000007602031620420181262F0C1507E207000000000008000000770203162042018109300C1507E207000000000008000000780203162042018129300C1507E20700000000000800000079020316204201810C310C1507E20700000000000800000080020316204201812C310C1507E20700000000000800000090020316204201810F320C1507E207000000000008000000910203162042018132320C1507E207000000000008000000920203162042018115330C1507E207000000000008000000930203162042018135330C1507E207000000000008000000940203162042018118340C1507E207000000000008000000950203162042018138340C1507E20700000000000800000096020316204201811B350C1507E20700000000000800000097020316204201813B350C1507E20700000000000800000098020316204201811E360C1507E207000000000008000000990203162042018102370C1507E207000000000008000000000303162042018121370C1507E207000000000008000000010303162042018131370C1507E207000000000008000000020303162042018115380C1507E207000000000008000000030303162042018134380C1507E207000000000008000000040303162042018118390C1507E207000000000008000000050303162042018137390C1507E20700000000000800000006030316204201811B3A0C1507E20700000000000800000007030316204201813A3A0C1507E20700000000000800000008030316204201811E3B0C1507E207000000000008000000C50D0A"""

        val str2 = """681155462490000099010100001E00006D4172EF4C0474100008104201810209091707E20700285500000000000027170008104201810409091707E20700C01200000000000033030008104201810509091707E20700000000000000000098230008104201810709091707E2070024F400000000000096230008104201810909091707E20700D80E00000000000091230008104201810A09091707E20700000000000000000097230008104201810C09091707E20700000000000000000093230008104201810D09091707E20700D8BD00000000000040030008104201811109091707E20700000000000000000039030008104201811209091707E20700581B00000000000038030008104201811409091707E20700201C00000000000037030008104201811509091707E20700640000000000000073100008104201811709091707E20700640000000000000038820108104201811909091707E20700640000000000000071100008104201811A09091707E20700640000000000000075100008104201811C09091707E20700A49C000000000000490D0A"""
        ch!!.writeInbound(Unpooled.buffer().apply { writeBytes(BcdString.fromBcdString(str).hexArray) })
        ch!!.writeInbound(Unpooled.buffer().apply { writeBytes(BcdString.fromBcdString(str2).hexArray) })
        lgr.info("packet parse okay.")
        Thread.sleep(5 * 1000)
    }

    @Test
    fun testDecodeNoHeader() {
//    68 11 55 44 34 12 00 00 43 03 00 00 01 01 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        val str = """
    55 44 34 12 00 00 43 03 00 00 01 01 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    82 01 42 10 09 00 16 95 82 01 42 10 09 00 16 96 82 01 42 10 09 00 16 97 82 01 42 10 09 00 16 99
    82 01 42 10 09 00 17 00 82 01 42 10 09 00 51 01 82 01 42 10 09 00 51 02 82 01 42 10 09 00 51 03
    82 01 42 10 09 00 51 04 82 01 42 10 09 00 51 05 82 01 42 10 09 00 51 06 82 01 42 10 09 00 51 07
    82 01 42 10 09 00 51 08 82 01 42 10 09 00 51 09 82 01 42 10 09 00 51 11 82 01 42 10 09 00 51 12
    82 01 42 10 09 00 51 13 82 01 42 10 09 00 51 14 82 01 42 10 09 00 51 15 82 01 42 10 09 00 51 16
    82 01 42 10 09 00 51 17 82 01 42 10 09 00 51 18 82 01 42 10 09 00 51 19 82 01 42 10 09 00 51 20
    82 01 42 10 09 00 51 21 82 01 42 10 09 00 51 22 82 01 42 10 09 00 51 23 82 01 42 10 09 00 51 24
    82 01 42 10 09 00 51 25 82 01 42 10 09 00 51 26 82 01 42 10 06 00 54 81 82 01 42 10 09 00 13 07
    82 01 42 10 09 00 13 08 82 01 42 10 09 00 13 12 82 01 42 10 09 00 13 14 82 01 42 10 09 00 13 24
    82 01 42 10 09 00 13 26 82 01 42 10 09 00 13 27 82 01 42 10 09 00 13 31 82 01 42 10 09 00 13 32
    82 01 42 10 09 00 13 33 82 01 42 10 09 00 13 35 82 01 42 10 09 00 13 38 82 01 42 10 09 00 13 39
    82 01 42 10 09 00 13 42 82 01 42 10 09 00 74 10 82 01 42 10 09 00 74 11 82 01 42 10 09 00 74 13
    82 01 42 10 09 00 74 14 82 01 42 10 09 00 74 15 82 01 42 10 09 00 74 16 82 01 42 10 09 00 74 17
    82 01 42 10 09 00 74 19 82 01 42 10 09 00 74 20 82 01 42 10 09 00 74 21 82 01 42 10 09 00 74 22
    82 01 42 10 09 00 74 23 82 01 42 10 09 00 74 24 82 01 42 10 09 00 74 25 82 01 42 10 09 00 74 26
    82 01 42 10 09 00 51 27 82 01 42 10 09 00 51 28 82 01 42 10 09 00 51 29 82 01 42 10 09 00 51 30
    82 01 42 10 09 00 51 31 82 01 42 10 09 00 51 32 82 01 42 10 09 00 51 33 82 01 42 10 09 00 51 34
    82 01 42 10 09 00 51 35 82 01 42 10 09 00 51 36 82 01 42 10 09 00 51 37 82 01 42 10 09 00 51 38
    82 01 42 10 09 00 51 39 82 01 42 10 09 00 51 40 82 01 42 10 09 00 51 41 82 01 42 10 09 00 69 94
    82 01 42 10 09 00 69 93 82 01 42 10 09 00 69 97 82 01 42 10 09 00 69 98 82 01 42 10 09 00 70 00
    82 01 42 10 09 00 69 95 82 01 42 10 09 00 69 99 82 01 42 10 09 00 74 51 82 01 42 10 09 00 74 53
    82 01 42 10 09 00 74 57 82 01 42 10 09 00 74 54 82 01 42 10 09 00 74 56 82 01 42 10 09 00 74 58
    82 01 42 10 09 00 74 52 82 01 42 10 09 00 60 54 82 01 42 10 09 00 60 67 82 01 42 10 09 00 60 76
    82 01 42 10 09 00 60 61 82 01 42 10 09 00 60 84 82 01 42 10 09 00 60 73 82 01 42 10 09 00 60 72
    82 01 42 10 09 00 60 71 82 01 42 10 09 00 60 62 82 01 42 10 09 00 60 69 82 01 42 10 09 00 60 58
    """
//    0b 0d 0a"""
        ch!!.writeInbound(Unpooled.buffer().apply { writeBytes(BcdString.fromBcdString(str).hexArray) })
    }

    @Test
    fun testDecodeNotEnough() {
        val str = """
    68 11 55 44 34 12 00 00 43 03 00 00 01 01 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    82 01 42 10 09 00 16 95 82 01 42 10 09 00 16 96 82 01 42 10 09 00 16 97 82 01 42 10 09 00 16 99
    82 01 42 10 09 00 17 00 82 01 42 10 09 00 51 01 82 01 42 10 09 00 51 02 82 01 42 10 09 00 51 03
    82 01 42 10 09 00 51 04 82 01 42 10 09 00 51 05 82 01 42 10 09 00 51 06 82 01 42 10 09 00 51 07
    82 01 42 10 09 00 51 08 82 01 42 10 09 00 51 09 82 01 42 10 09 00 51 11 82 01 42 10 09 00 51 12
    82 01 42 10 09 00 51 13 82 01 42 10 09 00 51 14 82 01 42 10 09 00 51 15 82 01 42 10 09 00 51 16
    82 01 42 10 09 00 51 17 82 01 42 10 09 00 51 18 82 01 42 10 09 00 51 19 82 01 42 10 09 00 51 20
    82 01 42 10 09 00 51 21 82 01 42 10 09 00 51 22 82 01 42 10 09 00 51 23 82 01 42 10 09 00 51 24
    82 01 42 10 09 00 51 25 82 01 42 10 09 00 51 26 82 01 42 10 06 00 54 81 82 01 42 10 09 00 13 07
    82 01 42 10 09 00 13 08 82 01 42 10 09 00 13 12 82 01 42 10 09 00 13 14 82 01 42 10 09 00 13 24
    82 01 42 10 09 00 13 26 82 01 42 10 09 00 13 27 82 01 42 10 09 00 13 31 82 01 42 10 09 00 13 32
    82 01 42 10 09 00 13 33 82 01 42 10 09 00 13 35 82 01 42 10 09 00 13 38 82 01 42 10 09 00 13 39
    82 01 42 10 09 00 13 42 82 01 42 10 09 00 74 10 82 01 42 10 09 00 74 11 82 01 42 10 09 00 74 13
    82 01 42 10 09 00 74 14 82 01 42 10 09 00 74 15 82 01 42 10 09 00 74 16 82 01 42 10 09 00 74 17
    82 01 42 10 09 00 74 19 82 01 42 10 09 00 74 20 82 01 42 10 09 00 74 21 82 01 42 10 09 00 74 22
    82 01 42 10 09 00 74 23 82 01 42 10 09 00 74 24 82 01 42 10 09 00 74 25 82 01 42 10 09 00 74 26
    82 01 42 10 09 00 51 27 82 01 42 10 09 00 51 28 82 01 42 10 09 00 51 29 82 01 42 10 09 00 51 30
    82 01 42 10 09 00 51 31 82 01 42 10 09 00 51 32 82 01 42 10 09 00 51 33 82 01 42 10 09 00 51 34
    82 01 42 10 09 00 51 35 82 01 42 10 09 00 51 36 82 01 42 10 09 00 51 37 82 01 42 10 09 00 51 38
    82 01 42 10 09 00 51 39 82 01 42 10 09 00 51 40 82 01 42 10 09 00 51 41 82 01 42 10 09 00 69 94
    82 01 42 10 09 00 69 93 82 01 42 10 09 00 69 97 82 01 42 10 09 00 69 98 82 01 42 10 09 00 70 00
    82 01 42 10 09 00 69 95 82 01 42 10 09 00 69 99 82 01 42 10 09 00 74 51 82 01 42 10 09 00 74 53
    82 01 42 10 09 00 74 57 82 01 42 10 09 00 74 54 82 01 42 10 09 00 74 56 82 01 42 10 09 00 74 58
    82 01 42 10 09 00 74 52 82 01 42 10 09 00 60 54 82 01 42 10 09 00 60 67 82 01 42 10 09 00 60 76
    82 01 42 10 09 00 60 61 82 01 42 10 09 00 60 84 82 01 42 10 09 00 60 73 82 01 42 10 09 00 60 72
    82 01 42 10 09 00 60 71 82 01 42 10 09 00 60 62 82 01 42 10 09 00 60 69 82 01 42 10 09 00 60 58
    """
//    0b 0d 0a"""
        ch!!.writeInbound(Unpooled.buffer().apply { writeBytes(BcdString.fromBcdString(str).hexArray) })
    }


    companion object {
        private val lgr = LoggerFactory.getLogger(JnrqTcpHandlerTest::class.java)

        @AfterClass
        fun afterClass() {
            Thread.sleep(1000)
            lgr.info("After-class...")

        }
    }
}